package com.zyk.plugin.costtime;

import com.zyk.Environment;
import com.zyk.plugin.JaTransformer;
import com.zyk.plugin.PluginConfig;
import com.zyk.plugin.PluginEntry;
import com.zyk.common.ConfigParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

public class CostTimeFilterPlugin implements PluginEntry {
    private static final Logger LOGGER = LoggerFactory.getLogger(CostTimeFilterPlugin.class);
    private static final String PLUGIN_NAME = "COST_TIME";

    PluginConfig pluginConfig;
    Environment environment;

    @Override
    public void init(Environment environment) {
        this.environment = environment;
        try {
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("costtime.yml");
            pluginConfig = new PluginConfig(ConfigParser.parseFromYaml(inputStream));

//            CostTimeFilter.setRules(pluginConfig.getBySection(PLUGIN_NAME));
        } catch (Exception e){
            LOGGER.error("init plugin failed.", e);
        }
    }

    @Override
    public List<JaTransformer> getJaTransformers() {
        return Arrays.asList(new CostTimeTransformer());
    }

    @Override
    public String getName() {
        return PLUGIN_NAME;
    }
    @Override
    public String getDescription() {
        return "A plugin for the ja, it can calculate methods time-costed\n.";
    }


}